home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Musik / Misc / Amster / Source / rexx.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-27  |  2.8 KB  |  121 lines

  1. /*
  2. ** ARexx Support
  3. */
  4.  
  5. #include "include/config.h"
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10.  
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <proto/rexxsyslib.h>
  14. #include <rexx/storage.h>
  15.  
  16. #include "include/mui.h"
  17. #include "include/search.h"
  18. #include "include/gui.h"
  19. #include "include/rexx.h"
  20. #include "amster_Cat.h"
  21.  
  22. MUIF rexx_con(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  23. MUIF rexx_dis(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  24. MUIF rexx_ison(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  25. MUIF rexx_search(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  26. MUIF rexx_sstat(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  27.  
  28. struct Hook rexx_conHook = { {0,0}, &rexx_con, NULL, NULL };
  29. struct Hook rexx_disHook = { {0,0}, &rexx_dis, NULL, NULL };
  30. struct Hook rexx_isonHook = { {0,0}, &rexx_ison, NULL, NULL };
  31. struct Hook rexx_searchHook = { {0,0}, &rexx_search, NULL, NULL };
  32. struct Hook rexx_sstatHook = { {0,0}, &rexx_sstat, NULL, NULL };
  33.  
  34. struct MUI_Command rexx_cmds[] = {
  35.     { "connect", NULL, 0, &rexx_conHook },
  36.     { "disconnect", NULL, 0, &rexx_disHook },
  37.     { "isonline", NULL, 0, &rexx_isonHook },
  38.     { "search", "TITLE/A", 1, &rexx_searchHook },
  39.     { "searchstate", NULL, 0, &rexx_sstatHook },
  40.     { NULL, NULL, 0, NULL }
  41. };
  42.  
  43.  
  44. MUIF rexx_con(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  45. {
  46.     if (!gui_napon) nap_login();
  47.     return(0);
  48. }
  49.  
  50.  
  51. MUIF rexx_dis(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  52. {
  53.     nap_logout();
  54.     set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  55.     return(0);
  56. }
  57.  
  58.  
  59. MUIF rexx_ison(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  60. {
  61.     if (gui_napon) return(1); else return(0);
  62. }
  63.  
  64.  
  65. MUIF rexx_search(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  66. {
  67.     DoMethod(gui->searchpanel, SEARCH_GO, array[0]);
  68.     return(0);
  69. }
  70.  
  71.  
  72. MUIF rexx_sstat(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  73. {
  74.     return((ULONG)search_state);
  75. }
  76.  
  77.  
  78. u_long rexx_sendcommand(char *port, char *com)
  79. {
  80.     struct MsgPort *me,*him;
  81.     struct RexxMsg *rmsg;
  82.     u_long rc=0;
  83.  
  84.     if(me=CreateMsgPort()) {
  85.         if(rmsg=CreateRexxMsg(me,NULL,NULL)) {
  86.             if(rmsg->rm_Args[0]=CreateArgstring(com,strlen(com))) {
  87.                 rmsg->rm_Action = RXCOMM;
  88.                 Forbid();
  89.                 if(him=FindPort(port)) {
  90.                     PutMsg(him,(struct Message *)rmsg);
  91.                     WaitPort(me);
  92.                     GetMsg(me);
  93.                     rc = rmsg->rm_Result1;
  94.                 }
  95.                 Permit();
  96.                 DeleteArgstring(rmsg->rm_Args[0]);
  97.             }
  98.             DeleteRexxMsg(rmsg);
  99.         }
  100.         DeleteMsgPort(me);
  101.     }
  102.     return(rc);
  103. }
  104.  
  105.  
  106. void rexx_execute(char *com, char *argfmt, ...)
  107. {
  108.     static char buf[1024];
  109.     char *p;
  110.     va_list ap;
  111.  
  112.     p = buf + sprintf(buf,"Run <>NIL: RexxC:RX %s ",com);
  113.     if(argfmt) {
  114.         va_start(ap,argfmt);
  115.         vsprintf(p,argfmt,ap);
  116.         va_end(ap);
  117.     }
  118.  
  119.     Execute(buf,0,0);
  120. }
  121.